package com.springsecurity.model.common;

import com.springsecurity.model.exceptions.IncorrectAttributeException;
import java.util.Map;
import java.util.Set;

/**
 *
 * @author evob0413
 */
public class ModelObject {
    
    private int id;
    private String name;
    private String description;
    private int objectType;
    private Map<Integer, Object> parameters;

    public ModelObject(int id, String name, String description, int objectType, Map<Integer, Object> parameters) {
        this.id = id;
        this.name = name;
        this.description = description;
        this.objectType = objectType;
        this.parameters = parameters;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getDescription() {
        return description;
    }

    public int getObjectType() {
        return objectType;
    }

    public Map<Integer, Object> getParameters() {
        return parameters;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setObjectType(int objectType) {
        this.objectType = objectType;
    }

    public void setParameters(Map<Integer, Object> parameters) {
        this.parameters = parameters;
    }
    
    public Object getParameter(int attrId) {
        return parameters.get(attrId);
    }
    
    public void setParameter(int attrId, Object parameter) 
            throws IncorrectAttributeException {
        if(!parameters.containsKey(attrId)) {
            throw new IncorrectAttributeException("Attribute " + attrId 
                    + " is not presented on object " + id);
        }
        parameters.remove(attrId);
        parameters.put(attrId, parameter);
    }
    
    public Set<Integer> getAllAttributeIds() {
        return parameters.keySet();
    } 
    
}
